cmake_minimum_required(VERSION 3.20)

##### QT #####
find_package(Qt5 REQUIRED COMPONENTS
    Core
    Gui
    Widgets
    Multimedia
    MultimediaWidgets
    Concurrent       # ← 多加这一行
    )

##### opencv #####
# find_package(OpenCV REQUIRED)
if(UNIX)
set(OPENCV_LIB_PATH
    /usr/lib
)
set(OPENCV_INCLUDE_PATH
    /usr/include/opencv4/
)
file(GLOB OPENCV_LIBS /usr/lib/libopencv*.so)

else() # windows
set(OPENCV_LIB_PATH
    ${CMAKE_SOURCE_DIR}/3rdlibs/opencv481/x64/vc16/lib
)
set(OPENCV_INCLUDE_PATH
    ${CMAKE_SOURCE_DIR}/3rdlibs/opencv481/include
)
file(GLOB OPENCV_LIBS ${OPENCV_LIB_PATH}/*d.lib)

endif()

add_library(opencv INTERFACE)
target_link_libraries(opencv INTERFACE ${OPENCV_LIBS})
target_include_directories(opencv INTERFACE ${OPENCV_INCLUDE_PATH})
target_link_directories(opencv INTERFACE ${OPENCV_LIB_PATH})

##### onnxruntime #####
if(UNIX)
set(ONNXRUNTIME_LIB_PATH
    /lib
    /opt/cuda/lib
)
set(ONNXRUNTIME_INCLUDE_PATH
    /usr/include/onnxruntime/
)
file(GLOB ONNXRUNTIME_LIBS /usr/lib/libonnxruntime.so) # onnxruntime .lib

else() # windows
set(ONNXRUNTIME_PATH
    ${CMAKE_SOURCE_DIR}/3rdlibs/onnxruntime-win-x64-gpu-1.19.2
)
set(ONNXRUNTIME_LIB_PATH
    ${ONNXRUNTIME_PATH}/lib
)
set(ONNXRUNTIME_INCLUDE_PATH
    ${ONNXRUNTIME_PATH}/include
)
file(GLOB ONNXRUNTIME_LIBS ${ONNXRUNTIME_LIB_PATH}/onnxruntime.lib)

endif()

add_library(onnxruntime INTERFACE)
target_link_libraries(onnxruntime INTERFACE ${ONNXRUNTIME_LIBS})
target_include_directories(onnxruntime INTERFACE ${ONNXRUNTIME_INCLUDE_PATH})
target_link_directories(onnxruntime INTERFACE ${ONNXRUNTIME_LIB_PATH})
# find_package(onnxruntime REQUIRED)

##### ffmpeg #####
if(UNIX)
set(FFMPEG_LIB_PATH
    /usr/lib
)
set(FFMPEG_LIBS
    /usr/lib/libavfilter.so
    /usr/lib/libavformat.so
    /usr/lib/libavcodec.so
    /usr/lib/libavutil.so
    /usr/lib/libswscale.so
    /usr/lib/libswresample.so
)

else() # windows
set(FFMPEG_LIB_PATH
    ${CMAKE_SOURCE_DIR}/3rdlibs/ffmpeg/lib
)
set(FFMPEG_INCLUDE_PATH
    ${CMAKE_SOURCE_DIR}/3rdlibs/ffmpeg/include
 )
set(FFMPEG_LIBS
    ${FFMPEG_LIB_PATH}/avfilter.lib
    ${FFMPEG_LIB_PATH}/avformat.lib
    ${FFMPEG_LIB_PATH}/avcodec.lib
    ${FFMPEG_LIB_PATH}/avutil.lib
    ${FFMPEG_LIB_PATH}/swscale.lib
    ${FFMPEG_LIB_PATH}/swresample.lib
)

endif()

add_library(ffmpeg INTERFACE)
target_link_libraries(ffmpeg INTERFACE ${FFMPEG_LIBS})
target_include_directories(ffmpeg INTERFACE ${FFMPEG_INCLUDE_PATH})
target_link_directories(onnxruntime INTERFACE ${FFMPEG_LIB_PATH})

##### elawidget #####
if(UNIX)
set(ELAWIDGET_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rdlibs/elawidget/include)
set(ELAWIDGET_LIB_DIR ${CMAKE_SOURCE_DIR}/3rdlibs/elawidget/lib)
file(GLOB ELAWIDGET_LIBS ${ELAWIDGET_LIB_DIR}/*.so)

else() # windows
set(ELAWIDGET_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rdlibs/elawidgettools/include)
set(ELAWIDGET_LIB_DIR ${CMAKE_SOURCE_DIR}/3rdlibs/elawidgettools/lib)
file(GLOB ELAWIDGET_LIBS ${ELAWIDGET_LIB_DIR}/*.lib)

endif()

add_library(elawidget INTERFACE)
target_link_libraries(elawidget INTERFACE ${ELAWIDGET_LIBS})
target_include_directories(elawidget INTERFACE ${ELAWIDGET_INCLUDE_DIR})
target_link_directories(elawidget INTERFACE ${ELAWIDGET_LIB_DIR})

##### whisper #####
set(WHISPER_INCLUDE_DIR
    ${CMAKE_SOURCE_DIR}/3rdlibs/whisper/include
    ${CMAKE_SOURCE_DIR}/3rdlibs/whisper/include/ggml)
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/3rdlibs/whisper/lib)

if(UNIX)
file(GLOB WHISPER_LIBS ${WHISPER_LIB_DIR}/*.so ${WHISPER_LIB_DIR}/libcommon.a)

else() # windows
file(GLOB WHISPER_LIBS ${WHISPER_LIB_DIR}/*.lib)

endif()

add_library(whisper INTERFACE)
target_link_libraries(whisper INTERFACE ${WHISPER_LIBS})
target_include_directories(whisper INTERFACE ${WHISPER_INCLUDE_DIR})
target_link_directories(whisper INTERFACE ${WHISPER_LIB_DIR})
